package com.scuec.groupfive.mapper;

import com.scuec.groupfive.entity.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserClientMapper {
    @Select("SELECT * FROM users")
    List<UserInfo> getUserList();

    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    UserInfo getUserById(Integer userId);

    @Update("UPDATE users SET status = #{status} WHERE user_id = #{userId}")
    int updateUserStatus(@Param("userId") Integer userId, @Param("status") Integer status);

    @Update("UPDATE users SET username = #{username}, email = #{email}, phone = #{phone}, " +
            "real_name = #{real_name}, gender = #{gender}, avatar = #{avatar}, " +
            "school = #{school}, target_school = #{target_school}, exam_year = #{exam_year} " +
            "WHERE user_id = #{user_id}")
    int updateUser(UserInfo userInfo);

    @Insert("INSERT INTO users (username, password, email, phone, real_name, gender, " +
            "avatar, school, target_school, exam_year, role, status) " +
            "VALUES (#{username}, #{password}, #{email}, #{phone}, " +
            "#{real_name}, #{gender}, #{avatar}, #{school}, " +
            "#{target_school}, #{exam_year}, #{role}, #{status})")
    int addUser(UserInfo userInfo);


    @Update("UPDATE users SET status = 0 WHERE user_id = #{userId}")
    int deleteUser(Integer userId);
}